<?php
function SelServidor($servidor)
{
     require "conexao1.inc.php";
     $sql = sprintf("SELECT servidor,db,usuario,senha,apelido,diretorio FROM Tables WHERE builder='1' ORDER BY servidor");
     $result = mysql_query($sql, $dbctl);
     if($result == 0)
     {
          printf("Falha: %s\n", mysql_error($dbctl));
          printf("%s\n", $sql);
          exit();
     }
     if(mysql_num_rows($result) > 0)
     {
          printf("<select name=\"APELIDO\" id=\"APELIDO\">\n");
          while($myrow = mysql_fetch_row($result))
          {
               if($myrow[0] == $servidor)
               {
                    printf("  <option value='$myrow[0]' selected='selected'>$myrow[4]</option>\n");
               }
               else
               {
                    printf("  <option value='$myrow[0]'>$myrow[4]</option>\n");
               }
          }
          printf("</select>\n");
     }
     mysql_close($dbctl);
}
function getApelido($servidor)
{
     $ret = '#';
     require "conexao1.inc.php";
     $sql = sprintf("SELECT diretorio FROM Tables WHERE builder='1' AND servidor='$servidor'");
     $result = mysql_query($sql, $dbctl);
     if($result == 0)
     {
          printf("Falha: %s\n", mysql_error($dbctl));
          printf("%s\n", $sql);
          exit();
     }
     if(mysql_num_rows($result) > 0)
     {
          while($myrow = mysql_fetch_row($result))
          {
               $ret = $myrow[0];
          }
     }
     mysql_close($dbctl);
     return $ret;
}
$servidor = "";
if(isset($_REQUEST['AP']))
{
     $servidor = $_REQUEST['AP'];
     $url = getApelido($servidor);
}
if(isset($_REQUEST['DIRETORIO']))
{
     $url = $_REQUEST['DIRETORIO'];
}
if(!isset($url))
{
     $site = " href='../NewBuilder'";
}
else
{
     $site = " href='../$url' target='_new'";
}
?>
<br />
<div align='center'>
     <p align='center'>
          <font size='5' color='#8080FF'><b>Dados para o Construtor</b>
          </font>
     </p>
     <br />
     <form method='get' name='frmBuilder' action='index.php'>
          <input type='hidden' name='Build' value='1' />
          <table border="0" align="center" cellpadding="1" cellspacing="1">
               <tr>
                    <th align='right'>Selecionar Servidor:</th>
                    <td align='left'><?php SelServidor($servidor); ?></td>
               </tr>
               <tr>
                    <th align='right'>Direitos:</th>
                    <td align="left"><select name='Dir'><option value="1">Sim</option>
                              <option value="">Nao</option>
                         </select>
                    </td>
               </tr>
               <tr>
                    <th align='right'>Sessao:</th>
                    <td align="left"><input type='text' name="Session" value="USER" /></td>
               </tr>
               <tr>
                    <th align='right'>Adicionar Agenda:</th>
                    <td align="left"><input type='checkbox' name="AGENDA"/></td>
               </tr>
               <tr>
                    <th align='right'>Adicionar iso-8859-1:</th>
                    <td align="left"><input type='checkbox' name="ISO"/></td>
               </tr>
               <tr>
                    <th align='right'>Adicionar utf8:</th>
                    <td align="left"><input type='checkbox' checked='checked' name="UTF8" /></td>
               </tr>
               <tr>
                    <th align='right'>Adicionar Logotipo:</th>
                    <td align="left"><input type='checkbox' checked='checked' name="LOGOTIPO" /></td>
               </tr>
               <tr>
                    <th align='right'>Header:</th>
                    <td align="left"><input type='text' name="Header"/></td>
               </tr>
               <tr>
                    <th align='right'>Itens por Aba:</th>
                    <td align="left"><input type='text' name="ITENS" value='8'/></td>
               </tr>
               <tr>
                    <th align='right'>Debug:</th>
                    <td align="left"><input type='checkbox' name="Debug"/></td>
               </tr>
               <tr>
                    <th align='right'>Montagem:</th>
                    <td align="left"><input type='checkbox' name="Montagem"/></td>
               </tr>
               <tr>
                    <th align='right'>Remover Arquivos:</th>
                    <td align="left"><input type='checkbox' name="UnBuild"/></td>
               </tr>
               <tr>
                    <th align='right'>Gerar Aviso:</th>
                    <td align="left"><input type='checkbox' checked='checked' name="Aviso"/></td>
               </tr>
               <tr>
                    <th align='right'>Incluir Chat:</th>
                    <td align="left"><input type='checkbox' name="CHAT"/></td>
               </tr>
               <tr>
                    <th align='right'>Menu:</th>
                    <td align="left">
                         <select name="Menu">
                              <option value="Novo">Novo</option>
                              <option value="Menu1">Menu1</option>
                              <option value="Menu2">Menu2</option>
                              <option value="Maujor">Maujor</option>
                              <option value="Potato" selected="selected">Potato</option>
                              <option value='Antigo'>Antigo</option>
                              <option value="Sem">Sem</option>
                         </select></td>
               </tr>
               <tr>
                    <th align='right'>Tabela:</th>
                    <td align="left"><input type='radio' name="Tabela" value="Nova"/>Nova&nbsp;<input type='radio' name="Tabela" value="Antiga" />Antiga&nbsp;<input type='radio' name="Tabela" value="Jqgrid" checked="checked"/>Jqgrid</td>
               </tr>
          </table>
          <table border='0'>
               <tr>
                    <td><input type="submit" value="Gerar" />
                    </td>
                    <td><input type="reset" value="Reset" />
                    </td>
               </tr>
          </table>
     </form>
     <a<?php echo $site;?>>Site</a>
</div>
